package middleware

import (
	"github.com/gin-gonic/gin"
)

// 中间件 - 验证产品线
func HandlerBizProductLine() gin.HandlerFunc {
	return func(c *gin.Context) {
		productLine := GetBizProductLine(c)
		if productLine == "" {
			abortRequest(c, 99999, "biz_product_line not found", nil)
			return
		}

		// 产品线字段兼容
		bizProductLine := 0
		if productLine == BizProductLineK12 || productLine == BizProductLineK12New {
			bizProductLine = 1
		} else if productLine == BizProductForeign || productLine == BizProductForeignNew {
			bizProductLine = 2
		} else if productLine == BizProductLineZhiKang {
			bizProductLine = 3
		} else {
			abortRequest(c, 99999, "biz_product_line error", nil)
			return
		}

		c.Set(NvCtxBizProductLine, bizProductLine)

		c.Next()
	}
}
